///////////////////////////////////////////////////////////////////////////////
// The Archimeds project 
//
// C++ Implementation: dlgservcon
//
// Description: 
//
//
// Author: Archimedes Projekt <thelsb@gmail.com>, (C) 2007
//
// Copyright: See COPYING file that comes with this distribution
////////////////////////////////////////////////////////////////////////////////
#include "dlgservcon.h"
#include "hpsceventthread.h"
#include "secservconmain.h"
#include "secservconinflation.h"
#include "ui_imp/ui_servconmain.h"
#include "ui_imp/ui_servconinflation.h"
#include <iostream>
#include <QSettings>


DlgServCon::DlgServCon(HPSCEventThread *hpscEventThread,QWidget *parent)
 : QWidget(parent)
{
    int headerHight = 101;
    QRect rect;
    this->setAutoFillBackground(true);
    ui.setupUi(this);
    QPixmap bgpixmap = QPixmap(":images/modules/servcon/bkg_servcon.png");
    if(bgpixmap.isNull()) std::cout<<"DlgServCon: null background pixmap"<<std::endl;
    QPalette p = this->palette();
    p.setBrush(this->backgroundRole(),QBrush(bgpixmap));
    this->setPalette(p);
   
     m_power = new FrmPower(FrmPower::C,FrmPower::D,this);
     rect.setRect(0,headerHight,580,250);
     m_power->setGeometry(rect);
//     m_commSettings->setGeometry(m_power->width()+40,headerHight+70,409,206);
     m_power->setHPSCEventThread(hpscEventThread);
    int index = 0; 
    ui.stkSections->insertWidget(index,new SecServConMain());
    index++;
    index++;
    ui.stkSections->insertWidget(index,new SecServConInflation());

    ui.stkSections->setCurrentIndex(0);

     connect(this,SIGNAL(sig_hkp(HkpCommand)),this,SLOT(readHkp(HkpCommand)));
     connect(this,SIGNAL(sig_hkp(HkpCommand)),m_power,SLOT(getHkpStatus(HkpCommand)));
     connect(m_power,SIGNAL(sig_busStatus(FrmPower::BUS,FrmPower::POWER_STAT)),this,SIGNAL(sig_busStatus(FrmPower::BUS,FrmPower::POWER_STAT)));
}


DlgServCon::~DlgServCon()
{
}


/*!
    \fn DlgServCon::readHkp(QHkp::port port, quint8 data)
 */
void DlgServCon::readHkp(HkpCommand hkpPacket)
{
    //qDebug()<<"DlgServCon::readHkp";
if(hkpPacket.port == QHkp::A)
    {
        if(hkpPacket.type == READ_IN)
        {
            QLabel *umbilical = ((SecServConMain*)ui.stkSections->widget(0))->ui.lblUmbilical;
            if(hkpPacket.data & UMBILICAL_CONN) 
            {
                if(umbilical->text()!="Connected")
                {
                    QPalette p = umbilical->palette();  
                    p.setColor(QPalette::WindowText,Qt::green);
                    umbilical->setPalette(p); 
                    umbilical->setText("Connected");
                }
            }
            else 
                {
                    if(umbilical->text()!="Not Connected") 
                    {
                        QPalette p = umbilical->palette();  
                        p.setColor(QPalette::WindowText,Qt::red);
                        umbilical->setPalette(p); 
                        umbilical->setText("Not Connected");
                    }
                }
        }
    }
}


/*!
    \fn DlgServCon::selectSection(int i)
 */
void DlgServCon::selectSection(int i)
{
    ui.stkSections->setCurrentIndex(i);
}
